/**
 * @file teacher.js
 * @description 教师管理API请求
 * @created 2024-07-10
 */

import request from '@/utils/request'

// 基础URL
const BASE_URL = '/api/admin'

/**
 * 获取学院列表
 * @returns {Promise} 学院列表
 */
export function getCollegesList() {
  return request({
    url: `${BASE_URL}/colleges/list/`,
    method: 'get'
  })
}

/**
 * 获取特定学院的系部列表
 * @param {number} collegeId - 学院ID
 * @returns {Promise} 系部列表
 */
export function getDepartmentsByCollege(collegeId) {
  return request({
    url: `${BASE_URL}/colleges/${collegeId}/departments/`,
    method: 'get'
  })
}

/**
 * 获取特定系部的教师列表
 * @param {number} departmentId - 系部ID
 * @returns {Promise} 教师列表
 */
export function getTeachersByDepartment(departmentId) {
  return request({
    url: `${BASE_URL}/departments/${departmentId}/teachers/`,
    method: 'get'
  })
}

/**
 * 获取教师详情
 * @param {number} teacherId - 教师ID
 * @returns {Promise} 教师详情
 */
export function getTeacherDetail(teacherId) {
  return request({
    url: `${BASE_URL}/teachers/${teacherId}/detail/`,
    method: 'get'
  })
}

/**
 * 获取教师的教学任务
 * @param {number} teacherId - 教师ID
 * @returns {Promise} 教师的教学任务，包含课程和班级
 */
export function getTeacherAssignments(teacherId) {
  return request({
    url: `${BASE_URL}/teachers/${teacherId}/assignments/`,
    method: 'get'
  })
}

/**
 * 获取教师特定课程的班级列表
 * @param {number} teacherId - 教师ID
 * @param {number} courseId - 课程ID
 * @returns {Promise} 课程班级列表
 */
export function getTeacherCourseClasses(teacherId, courseId) {
  return request({
    url: `${BASE_URL}/teachers/${teacherId}/courses/${courseId}/classes/`,
    method: 'get'
  })
}

/**
 * 获取班级学生成绩
 * @param {number} teacherId - 教师ID
 * @param {number} courseId - 课程ID
 * @param {number} classId - 班级ID
 * @returns {Promise} 班级学生成绩
 */
export function getClassStudentGrades(teacherId, courseId, classId) {
  return request({
    url: `${BASE_URL}/teachers/${teacherId}/courses/${courseId}/classes/${classId}/grades/`,
    method: 'get'
  })
}

/**
 * 创建新教师
 * @param {object} data - 教师数据
 * @param {string} data.teacher_code - 教师工号
 * @param {string} data.name - 教师姓名
 * @param {number} data.department_id - 系ID
 * @param {number} data.college_id - 学院ID
 * @param {string} [data.gender] - 性别
 * @param {string} [data.title] - 职称
 * @param {string} [data.email] - 邮箱
 * @param {string} [data.phone] - 电话
 * @returns {Promise} 创建结果
 */
export function createTeacher(data) {
  return request({
    url: `${BASE_URL}/teachers/create/`,
    method: 'post',
    data
  })
}

/**
 * 更新教师信息
 * @param {number} teacherId - 教师ID
 * @param {object} data - 要更新的教师数据
 * @returns {Promise} 更新结果
 */
export function updateTeacher(teacherId, data) {
  return request({
    url: `${BASE_URL}/teachers/update/${teacherId}/`,
    method: 'put',
    data
  })
}

/**
 * 删除教师
 * @param {number} teacherId - 教师ID
 * @returns {Promise} 删除结果
 */
export function deleteTeacher(teacherId) {
  return request({
    url: `${BASE_URL}/teachers/delete/${teacherId}/`,
    method: 'delete'
  })
} 